<?php
	session_start();

	require_once 'photo.php';
	require_once 'configu.php';
	require_once 'database.php';
	require_once 'user.php';
	if (isset($_POST["operation"]))
	$operation = $_POST["operation"];
	else if(isset($_GET["op"]))
	$operation = $_GET["op"];
	
	if ($operation=='addcomment'){
		$username = $_SESSION["username"];
		database::query("INSERT INTO postkomen (IDPost, Teks, Username_Poster) 
			VALUES ('$_POST[idpost]','$_POST[cominput]','$username')");
	}
	else if ($operation=='getnotif'){
		$username = $_SESSION["username"];
		$last = $_GET["ls"];	
		$allNotif = user::getAllNotif($username);
		$nlist=mysql_num_rows($allNotif);
		$count = 0;
		
		if ($nlist!=0&&0<$last&&$last<$nlist)	mysql_data_seek($allNotif,$last);
		else if ($last>=$nlist)mysql_data_seek($allNotif,$nlist-1);
		while($count<3 && ($row = mysql_fetch_array($allNotif))){
			if ($row["Type"]==1){
				echo '<div class="not" style="font-weight:bold;cursor:pointer">';
				echo $row[Tagger].' has tagged you on his <a href="#">Wall</a>.';
				echo '</div>';
			}
			elseif ($row["Type"]==2){
				echo '<div class="not" style="font-weight:bold;cursor:pointer">';
				echo $row[Tagger].' has tagged you on his <a href="javascript:void();" onclick="photoDetail(\'big\',\''.$row[Tagger].'\','.$row[Identifier].');">Photo</a>.';
				echo '</div>';
			}else if ($row["Type"]==3){
				echo '<div class="not" style="font-weight:bold;cursor:pointer">';
				echo $row[Tagger].' has send you a <a href="#">Message</a><br/>.';
				echo '</div>';
			}
			$count++;
		}
		if ($nlist <= $last+3){
			echo '<input type="hidden" id="notifhbs" value="1"/>';
		}
	}
	else if ($operation=='getnnotif'){
		$username = $_SESSION["username"];
		$allNotif = user::getAllNotif($username);
		echo mysql_num_rows($allNotif);
	}
	
?>